package cn.tedu.ivos3.repair.service.impl;


import cn.tedu.ivos3.repair.mapper.RepairMapper;
import cn.tedu.ivos3.repair.pojo.dto.RepairQuery;
import cn.tedu.ivos3.repair.pojo.dto.RepairSaveParam;
import cn.tedu.ivos3.repair.pojo.entity.Repair;
import cn.tedu.ivos3.repair.pojo.vo.RepairVO;
import cn.tedu.ivos3.repair.service.RepairService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class RepairServiceImpl implements RepairService {
    @Autowired
    RepairMapper repairMapper;

    @Override
    public List<RepairVO> selectVehicle(RepairQuery repairQuery) {
        log.debug("查询车辆维修业务：{}", repairQuery);
        List<RepairVO> list = repairMapper.select(repairQuery);
        return list;
    }

    @Override
    public void saveVehicle(RepairSaveParam repairSaveParam) {
        log.debug("新增/编辑车辆维修业务:{}", repairSaveParam);
        Repair repair = new Repair();
        BeanUtils.copyProperties(repairSaveParam, repair);
        if (repair.getId() == null) {//新增
            repair.setCreateTime(new Date());
            repairMapper.insert(repair);
        } else {//更新
            repair.setUpdateTime(new Date());
            repairMapper.update(repair);
        }
    }

    @Override
    public void deleteVehicle(Long id) {
        log.debug("删除车辆维修业务：{}", id);
        repairMapper.delete(id);
    }

}
